<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class UserInvoice extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 可执行搜索的字段
     */
    public $searchable = [
        'user_id',
        'header_type',
        'type',
        'name',
        'duty_number',
        'drawer_phone',
        'is_default',
        'invoice_status'
    ];

    /**
     * 可批量赋值字段
     */
    public $fillable = [
        'user_id',
        'header_type',
        'type',
        'name',
        'duty_number',
        'drawer_phone',
        'email',
        'tell',
        'address',
        'bank',
        'card_number',
        'is_default',
    ];

    /**
     * 默认使用倒叙的字段
     */
    public $defaultSortCriteria = [
        'id,desc',
    ];

    /**
     * 发票状态
     */
    public $invoiceStatusEnum=[
        'notInvoiced' => '未开发票',
        'invoiced' => '已开发票',
        'refundInvoiced' => '退款发票'
    ];
    /**
     * 账单关联用户的id
     */
    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    /**
     * 发票记录关联订单
     */
    public function order()
    {
        return $this->hasOne(Order::class,'id','order_id');
    }

}
